/**********************************************************

@description:
*File Name:hashtable.c
*Author: ydx
*mail: yudongxiang93@163.com
*Create Time: Fri 09 May 2025 11:58:24 AM CST
**********************************************************/
#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
#include<string.h>

#define NUM 10
typedef struct hashlist{
	int num;
	char* data;
}hashlist;
hashlist* init(){
	hashlist* l=(hashlist*)malloc(sizeof(hashlist));
	assert(l);
	l->data=(char*)malloc(NUM*sizeof(char));
	assert(l);
	memset(l->data,0x0,NUM*sizeof(char));
	l->num=0;
	return l;
}

int hash(char data){
	return data % NUM;
}

void put(hashlist* l,char data){
	int code=hash(data);
	if(l->data[code]){
		int count=1;
		while(l->data[code]!=0){
			code=hash(hash(code)+count);
			count++;
		}
	}
	l->data[code]=data;
	l->num++;
}
void print_arr(char* arr){
	for(int i=0;i<NUM;i++){
		printf("i=%d:%c  ",i,arr[i]);
	}
	printf("\n");
}

int main(){
	hashlist* list=init();
	put(list,'A');
	put(list,'B');
	put(list,'C');
	put(list,'D');
	put(list,'E');
	put(list,'F');
	put(list,'G');
	put(list,'H');
	put(list,'I');
	put(list,'J');
	put(list,'K');
	put(list,'L');
	put(list,'M');
	put(list,'N');
	print_arr(list->data);

}
